/**
 * Written by Dustin Striplin & Phat Le
 */
package Actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JTable;

import Model.Author;
import Model.ProgramChair;
import Model.Reviewer;
import Model.SubProgramChair;

import View.ManuscriptView;

/**
 * Displays a selected manuscript
 * @author dustin striplin
 * @author Phat le
 *
 */
public class ViewManuscriptAction extends AbstractAction{

	private static final long serialVersionUID = 1L;
	private JTable table;
	private ProgramChair pc;
	private SubProgramChair spc;
	private Reviewer rvw;
	private Author ath;
	
	/**
	 * Phat le
	 * used by the program chair
	 * @param a_table The table to be manipulated
	 * @param a_pc the user
	 */
	public ViewManuscriptAction(final JTable a_table, final ProgramChair a_pc) {
		table = a_table;
		pc = a_pc;
		this.putValue(NAME, "View PC Manusript");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_V);
	}
	
	/**
	 * Phat le
	 * used by the sub program chair
	 * @param a_table the table to be manipulated
	 * @param a_spc the user
	 */
	public ViewManuscriptAction(final JTable a_table, final SubProgramChair a_spc) {
		table = a_table;
		spc = a_spc;
		this.putValue(NAME, "View SPC Manusript");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_V);
	}
	
	/**
	 * Phat le
	 * used by the reviewer
	 * @param a_table the table to be manipulated
	 * @param a_rvw the user
	 */
	public ViewManuscriptAction(final JTable a_table, final Reviewer a_rvw) {
		table = a_table;
		rvw = a_rvw;
		this.putValue(NAME, "View RVW Manusript");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_V);
	}
	
	/**
	 * Phat le
	 * used by the author
	 * @param a_table the table to be manipulated
	 * @param a_ath the user
	 */
	public ViewManuscriptAction(final JTable a_table, final Author a_ath) {
		table = a_table;
		ath = a_ath;
		this.putValue(NAME, "View ATH Manusript");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_V);
	}

	/**
	 * displays a paper
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if(table.getSelectedRow() != -1){
			ManuscriptView scriptWindow = new ManuscriptView();
			scriptWindow.setTitle("Manuscript");
			if(e.getActionCommand().equalsIgnoreCase("View PC Manusript")){
				scriptWindow.start(pc.viewManuscript(table)); 
			} else if (e.getActionCommand().equalsIgnoreCase("View SPC Manusript")){
				scriptWindow.start(spc.viewManuscript(table));
			} else if (e.getActionCommand().equalsIgnoreCase("View RVW Manusript")){
				scriptWindow.start(rvw.viewManuscript(table));
			} else {
				scriptWindow.start(ath.viewManuscript(table));
			}
		} else {
			JOptionPane.showMessageDialog(null, "Please select a manuscript");
		}
		
		
	}


}
